//
//  AdviceViewController.m
//  NewProject
//
//  Created by admin on 2017/6/16.
//  Copyright © 2017年 李航飞. All rights reserved.
//

#import "AdviceViewController.h"
#import <objc/runtime.h>
#import <objc/message.h>
@interface AdviceViewController ()
@property(nonatomic,strong)UIView *topView;
@property(nonatomic,strong)UILabel *headLabel;
@property(nonatomic,strong)UITextView *contentTextView;
@property(nonatomic,strong)UILabel *numLabel;
@property(nonatomic,strong)UIView *lineView;
@property(nonatomic,strong)UIButton *photoButton;
@property(nonatomic,strong)UILabel *maxLabel;
@property(nonatomic,strong)UIButton *commitButton;
@end

@implementation AdviceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"意见反馈";
    
    _topView = [[UIView alloc]init];
    _topView.backgroundColor = RGB0X(0xF8F9F6);
    _topView.frame = CGRectMake(0, 0, WIDTH, 8/WIDTH_6_SCALE);
    [self.view addSubview:_topView];
    
    _headLabel = [[UILabel alloc]init];
    _headLabel.frame = CGRectMake(15/WIDTH_6_SCALE, 24/WIDTH_6_SCALE, 200/WIDTH_6_SCALE, 15/WIDTH_6_SCALE);
    _headLabel.textColor = RGB0X(0x333333);
    _headLabel.font = FONT(15);
    _headLabel.text = @"请选择问题类型";
    [self.view addSubview:_headLabel];
    
    NSArray *array = @[@"商品种类",@"商品品质",@"软件功能",@"促销活动",@"配送服务",@"其他问题"];
    for (int i = 0; i<6; i++) {
        UIButton *typeButton = [UIButton buttonWithType:UIButtonTypeCustom];
        typeButton.layer.masksToBounds = YES;
        typeButton.layer.cornerRadius=2/WIDTH_6_SCALE;
        typeButton.layer.borderWidth = 1/WIDTH_6_SCALE;
        typeButton.layer.borderColor = RGB0X(0xE8E8E8).CGColor;
        [typeButton setTitle:array[i] forState:UIControlStateNormal];
//        typeButton.titleLabel.text = array[i];
        [typeButton setTitleColor:RGB0X(0x747474) forState:UIControlStateNormal];
        typeButton.titleLabel.font = FONT(13);
//        typeButton.titleLabel.textColor = RGB0X(0x747474);
        typeButton.frame = CGRectMake(21/WIDTH_6_SCALE+117/WIDTH_6_SCALE*(i%3), 55/WIDTH_6_SCALE+44*(i/3), 98/WIDTH_6_SCALE, 31/WIDTH_6_SCALE);
        [self.view addSubview:typeButton];
    }
    
    // 通过运行时，发现UITextView有一个叫做“_placeHolderLabel”的私有变量
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([UITextView class], &count);
    
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char *name = ivar_getName(ivar);
        NSString *objcName = [NSString stringWithUTF8String:name];
        NSLog(@"%d : %@",i,objcName);
    }
    
    _contentTextView = [[UITextView alloc] initWithFrame:CGRectMake(15/WIDTH_6_SCALE, 150/WIDTH_6_SCALE, [UIScreen mainScreen].bounds.size.width-30/WIDTH_6_SCALE, 225/WIDTH_6_SCALE)];
                                                                        [_contentTextView setBackgroundColor:RGB0X(0xF5F5F5)];
    _contentTextView.layer.cornerRadius = 5/WIDTH_6_SCALE;
    _contentTextView.layer.masksToBounds = YES;
                                                                        [self.view addSubview:_contentTextView];
                                                                        
                                                                        // _placeholderLabel
    UILabel *placeHolderLabel = [[UILabel alloc]init];
                                                                    placeHolderLabel.text = @"请您写下宝贵的建议，这都将帮助我们更好的完善产品";
                                                                        placeHolderLabel.numberOfLines = 0;
                                                                        placeHolderLabel.textColor = RGB0X(0xC8C8C8);
                                                                        [_contentTextView addSubview:placeHolderLabel];
                                                                        
                                                                        // same font
                                                                        _contentTextView.font = [UIFont systemFontOfSize:13.f];
                                                                        placeHolderLabel.font = [UIFont systemFontOfSize:13.f];
    
    [placeHolderLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_contentTextView.mas_left).offset(15/WIDTH_6_SCALE);
        make.top.equalTo(_contentTextView.mas_top).offset(15/WIDTH_6_SCALE);
        make.right.equalTo(_contentTextView.mas_right).offset(-15/WIDTH_6_SCALE);
    }];
    [self.view layoutIfNeeded];
                                                                            [_contentTextView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    
    _numLabel = [[UILabel alloc]init];
    _numLabel.text = @"300字以内";
    _numLabel.textColor = RGB0X(0x747474);
    _numLabel.font = FONT(14);
    _numLabel.frame = CGRectMake(260/WIDTH_6_SCALE, 123/WIDTH_6_SCALE, 100/WIDTH_6_SCALE, 14/WIDTH_6_SCALE);
    [self.contentTextView addSubview:_numLabel];
    
    _lineView = [[UIView alloc]init];
    _lineView.frame = CGRectMake(15/WIDTH_6_SCALE, 149/WIDTH_6_SCALE, WIDTH - 60/WIDTH_6_SCALE, 1/WIDTH_6_SCALE);
    _lineView.backgroundColor = RGB0X(0xE7E7E7);
    [_contentTextView addSubview:_lineView];
    
    _photoButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _photoButton.frame = CGRectMake(15/WIDTH_6_SCALE, 163/WIDTH_6_SCALE, 49/WIDTH_6_SCALE, 49/WIDTH_6_SCALE);
    [_photoButton setImage:[UIImage imageNamed:@"相机"] forState:UIControlStateNormal];
    [_photoButton addTarget:self action:@selector(photoButtonClick) forControlEvents:UIControlEventTouchUpInside];
    _photoButton.layer.borderWidth = 1/WIDTH_6_SCALE;
    _photoButton.layer.borderColor = RGB0X(0xE8E8E8).CGColor;
    [_contentTextView addSubview:_photoButton];
    
    _maxLabel = [[UILabel alloc]init];
    _maxLabel.text = @"最多3张";
    _maxLabel.textColor = RGB0X(0xC8C8C8);
    _maxLabel.font = FONT(12);
    _maxLabel.frame = CGRectMake(WIDTH-95/WIDTH_6_SCALE, 180/WIDTH_6_SCALE, 65/WIDTH_6_SCALE, 12/WIDTH_6_SCALE);
    [_contentTextView addSubview:_maxLabel];
    
    _commitButton = [UIButton buttonWithType:UIButtonTypeCustom];
    _commitButton.frame = CGRectMake(22/WIDTH_6_SCALE, 434/WIDTH_6_SCALE, WIDTH - 44/WIDTH_6_SCALE, 41/WIDTH_6_SCALE);
    _commitButton.backgroundColor = RGB0X(0xFFD601);
    [_commitButton setTitle:@"提交" forState:UIControlStateNormal];
    _commitButton.titleLabel.font = FONT(15);
    _commitButton.layer.cornerRadius = 3/WIDTH_6_SCALE;
    _commitButton.layer.masksToBounds = YES;
    [self.view addSubview:_commitButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
